package no.doomsday.sync 
{
	import com.adobe.utils.StringUtil;
	/**
	 * ...
	 * @author Andreas Rønning
	 */
	public class SyncPatternParser implements ISyncPattern
	{
		private var _events:Vector.<SyncPatternEvent> = new Vector.<SyncPatternEvent>();
		public function SyncPatternParser(source:String) 
		{
			var eventSplit:Array = StringUtil.trim(source).split(";");
			for (var i:int = 0; i < eventSplit.length; i++) 
			{
				if (eventSplit[i] == "") continue;
				eventSplit[i] = StringUtil.trim(eventSplit[i]);
				_events.push(new SyncPatternEvent(eventSplit[i]));
			}
		}
		
		/* INTERFACE clockwerk.ISyncPattern */
		
		public function getBPM(time:Number):Number
		{
			return 0;
		}
		
		public function getIsSilent(time:Number):Boolean
		{
			return false;
		}
		
	}

}
internal class SyncPatternEvent {
	private var _type:int;
	private var _value:int;
	public static const SILENCE:int = 0;
	public static const BEAT_START:int = 1;
	public static const BPM_CHANGE:int = 2;
	public var timeCode:Array;
	public var seconds:Number;
	public function SyncPatternEvent(input:String) {
		trace("new");
		var timeCode:Array = input.split(" ")[0].split(":");
		seconds = parseInt(timeCode[0]) * 60 + parseInt(timeCode[1]);
		trace("\tseconds", seconds);
		var key:String = input.split(" ")[1];
		if (key.indexOf("bpm")>-1) {
			_type = BPM_CHANGE;
			var slice:String = key.slice(0, key.indexOf("bpm"));
			_value = parseInt(slice);
			trace("\tBpm change; " + _value);
		}else {
			switch(key) {
				case "silence":
				_type = SILENCE;
				trace("\tSilence");
				break;
				case "beat":
				_type = BEAT_START;
				trace("\tBeat start");
				break;
			}
		}
	}
	public function get type():int { return _type; }
}